package yanyan.com.tochar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import yanyan.com.tochar.utils.ToastUtil;

public class FunsMusicActivity extends Activity {
    private OkHttpClient okHttpClient=new OkHttpClient();
    private EditText test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_funs_music);
        test=findViewById(R.id.test_ed);
    }



    public void getMusic(View view){
        RequestBody requestBody=new FormBody.Builder().
                add("input","十年")
                .add("filter","name")
                .add("type","netease")
                .add("page","1")
                .build();
        Request request=new Request.Builder().url("http://music.onlychen.cn/").post(requestBody).build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                ToastUtil.showLongToast(FunsMusicActivity.this,"失败");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        test.setText(string);
                    }
                });

            }
        });
    }
}
